﻿<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8 />
    <title></title>
    <link href="../../Content/jquery-easyui-1.3.1/themes/icon.css" rel="stylesheet" />
    <link href="../../Content/jquery-easyui-1.3.1/themes/default/easyui.css" rel="stylesheet" />
    <link href="../../Content/Site.css" rel="stylesheet" />
    <script src="../../Content/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
    <script src="../../Content/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
    <script src="../../Content/jquery-easyui-1.3.1/locale/easyui-lang-zh_CN.js"></script>
    @*修改时间格式的Js文件*@
    <script src="../../Content/jquery-easyui-1.3.1/datapattern2.js"></script>

    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>

    <script type="text/javascript">
        var roleid;

       
     $(function () {

            roleid = $('#RoleID').val();
           
            $("#tt").tree({
                url: '/Role/InitTree?RoleID=' + roleid,
                lines: true,
                checkbox: true,
                cascadeCheck: false,
                onCheck: function (node, checked) {
                    if (checked)
                    {
                        //子结点选中，父节点随之选中
                        var parentNode = $("#tt").tree('getParent', node.target);
                        if (parentNode != null) {
                            $("#tt").tree('check', parentNode.target);
                        }
                        ////父节点选中，子节点随之选中
                        //var childNode = $("#tt").tree('getChildren', node.target);
                       //if (childNode.length > 0) {
                        //        for (var i = 0; i < childNode.length; i++) {
                       //        $("#tt").tree('check', childNode[i].target);
                        //    }
                        //}

                    } else//父节点取消，子节点随之取消
                    {
                        var childNode = $("#tt").tree('getChildren', node.target);
                        if (childNode.length > 0) {
                            for (var i = 0; i < childNode.length; i++) {
                                $("#tt").tree('uncheck', childNode[i].target);
                            }
                        }
                    }
                }
            });
     });
        //全选
     function CheckedAll() { 
         var roots = $('#tt').tree('getRoots'), children, i, j;
         for (i = 0; i < roots.length; i++) {
            
             children = $('#tt').tree('getChildren', roots[i].target);
             
             for (j = 0; j < children.length; j++) $("#tt").tree('check', children[j].target);
         }
     }
        //修改角色权限
     function save() {
      
         //获取选中节点ID
         var checkeds = $('#tt').tree('getChecked');
         var actions = '';
         for (var i = 0; i < checkeds.length; i++) {
             if (actions != '') actions += ',';
             actions += checkeds[i].id;
             
         }
         if (actions == '') {
             $.messager.alert("提示", "不允许为空!");
         }
         else//修改角色权限信息
         {
          
            
             $.messager.confirm("修改角色权限", "修改角色权限时不仅改变该角色的权限信息，而且将会使拥有该角色的用户的子级用户的权限连带修改，您确认要修改吗？", function (DeleteInfo) {
                 if (DeleteInfo) {
                     //
                     $.post("/Role/UpdateRoleActionInfoes", { RoleID: roleid, selectedActionInfoIDS: actions }, function (data) {
                         if (data == "OK") {
                             $.messager.alert("友情提示", "修改角色权限成功!");
                             window.location.reload();//刷新当前页面.
                         }
                         else {
                             $.messager.alert("友情提示", data);
                         }
                     });
                 }
             });
            

         }
        

          
       
           
         
        }
       
    </script>

   
</head>

<body>
    <h2>为角色授权</h2>
    
   
    <div class="easyui-panel" style="padding:5px">
        <ul id="tt"></ul>
    </div>

    <input type="button" value="设置" onclick="save()" />
    <input type="button" value="全选" onclick="CheckedAll()" />

    <input class="easyui-validatebox" id="RoleID" name="RoleID" value="@ViewBag.RoleID" hidden="hidden" />

  
</body>

</html>











